#include "qapplication.h"
#include "qpushbutton.h"
#include "qlist.h"
#include "qwindowsystem_qws.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	QApplication app(argc,argv, QApplication::GuiServer);

	QPushButton *hello = new QPushButton("Hello World.",0);
	qDebug("hello button addr:0x%x\n",hello);
	qDebug("QWSServr addr: %lx\n",qwsServer);
	hello->resize(700,500);
	hello->move(10,10);
	
	hello->show();

	app.setMainWidget(hello);

	int pid = fork();
	int ret;
	if(pid == 0)
	{
		ret = execl("/tmp/hello_client",(char*)0);
		if(ret == -1)
		{
			perror("execl qwsclient:");
		}
		exit(0);
	}

	sleep(5);
	QList<QWSWindow> qwswindow = qwsServer->clientWindows();
	int cnt = qwswindow.count();
	qDebug("QWSWindow count:%d\n", cnt);
	int i = 0;
	for(;i < cnt; i++)
	{
		QWSWindow *pw = qwswindow.at(i);
		QWSClient *pwc = pw->client();
		qDebug("QWSWindow %d :[winId]%d [name]%s [caption] %s [isVisible] %d" \
				"[clientId] %d [clientID] %s\n",i,pw->winId(),pw->name().ascii(),pw->caption().ascii(),
				pw->isVisible(), pwc->clientId(), pwc->identity().ascii());
	}


	return app.exec();
}


